﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using PMatch.Formats.SequenceSample;
using PMatch.Sampling;

namespace PMatch.Experimentation
{
	public class ExperimentUnit
	{
		public samples Train { get; set; }
		public samples Test { get; set; }

		[DocumentColumnIndex(101)]
		public SampleWindow Window { get; set; }

		[DocumentColumnIndex(100)]
		public int Site { get; set; }

		public TimeSpan Elapsed { get; set; }

		public void SetStats(int tp, int fp)
		{
			TPc = tp;
			FPc = fp;
			TNc = Test.negative.Count - fp;
			FNc = Test.positive.Count - tp;
			TCc = TPc + TNc;
			FCc = FPc + FNc;
		}

		public void SetCounts()
		{
			TrainCount = Train.Count;
			TestCount = Test.Count;
			TrainPositiveCount = TrainPositiveCount;
			TrainNegativeCount = TrainNegativeCount;
			TestPositiveCount = TestPositiveCount;
			TestNegativeCount = TestNegativeCount;
		}

		public int TrainCount { get; set; }
		public int TestCount { get; set; }
		public int TrainPositiveCount { get; set; }
		public int TrainNegativeCount { get; set; }
		public int TestPositiveCount { get; set; }
		public int TestNegativeCount { get; set; }

		// Contadores				
		[DocumentColumnIndex(700)]
		public int TPc { get; set; }
		[DocumentColumnIndex(701)]
		public int TNc { get; set; }
		[DocumentColumnIndex(702)]
		public int FPc { get; set; }
		[DocumentColumnIndex(703)]
		public int FNc { get; set; }

		[DocumentColumnIndex(704)]
		public int TCc { get; set; }
		[DocumentColumnIndex(705)]
		public int FCc { get; set; }


		// Porcentajes
		[DocumentColumnIndex(200)]
		public double TPp { get { return TPc / (double)TestPositiveCount; } }
		[DocumentColumnIndex(201)]
		public double TNp { get { return TNc / (double)TestNegativeCount; } }
		[DocumentColumnIndex(202)]
		public double FPp { get { return FPc / (double)TestNegativeCount; } }
		[DocumentColumnIndex(203)]
		public double FNp { get { return FNc / (double)TestPositiveCount; } }

		[DocumentColumnIndex(204)]
		public double TCp { get { return TCc / (double)TestCount; } }
		[DocumentColumnIndex(205)]
		public double FCp { get { return FCc / (double)TestCount; } }

		public double TFRatio { get { return TCc / (double)FCc; } }

		[DocumentColumnIndex(500)]
		public double Accuracy { get { return TCp; } }
		[DocumentColumnIndex(501)]
		public double Precision { get { return TPp; } }
		[DocumentColumnIndex(502)]
		public double Specificity { get { return TNc / (double)(TNc + FPc); } }
		[DocumentColumnIndex(503)]
		public double Sensitivity { get { return TPc / (double)(TPc + FNc); } }
		[DocumentColumnIndex(504)]
		public double CC { get { return ((double)TPc * (double)TNc - (double)FPc * (double)FNc) / Math.Sqrt((double)(TPc + FNc) * (double)(TPc + FPc) * (double)(TNc + FPc) * (double)(TNc + FNc)); } }
	}
}
